{% extends '_modal.html' %}
{% load i18n %}
{% block modal_id %}test_user_login_modal{% endblock %}
{% block modal_title%}{% trans "Test LDAP user login" %}{% endblock %}
{% block modal_comment %}{% trans "Save the configuration before testing the login" %}{% endblock %}
{% block modal_body %}
<form class="form-horizontal" role="form" style="padding-top: 20px" onkeydown="if(event.keyCode==13){ $('#btn_test_user_login_modal_confirm').trigger('click'); return false;}">
    {% csrf_token %}
    <div class="form-group">
        <label class="col-sm-2 control-label">{% trans "Username" %}: </label>
        <div class="col-sm-10">
            <input class="form-control" id="id_username_auth" type="text" name="username" placeholder="{% trans 'Please input username' %}"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">{% trans "Password" %}: </label>
        <div class="col-sm-10">
            <input class="form-control" id="id_password_auth" type="password" name="password" placeholder="{% trans 'Please input password' %}"/>
        </div>
    </div>
</form>
<script>

$(document).ready(function () {

}).on("show.bs.modal", "#test_user_login_modal", function () {
    $('#id_password_auth').val('');
}).on('click', '#btn_test_user_login_modal_confirm', function(){
    var username = $('#id_username_auth').val();
    var password = $('#id_password_auth').val();

    var data = {
        'username': username, 'password': password
    };

    var the_url = "{% url 'api-settings:ldap-testing-login' %}";

    function error(message) {
        toastr.error(message)
    }

    function success(message) {
        toastr.success(message);
        $("#test_user_login_modal").modal('hide');
    }
    requestApi({
        url: the_url,
        body: JSON.stringify(data),
        method: "POST",
        flash_message: false,
        success: success,
        error: error
    });
})

</script>
{% endblock %}
{% block modal_confirm_id %}btn_test_user_login_modal_confirm{% endblock %}
